package com.burstly.lib.component.networkcomponent.burstly;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.FrameLayout;
import com.burstly.lib.component.networkcomponent.IActivityLifeCycleAware;
import com.burstly.lib.component.networkcomponent.burstly.html.CloseableContainer;
import com.burstly.lib.util.LoggerExt;

public class FullscreenOverlayContainer<T extends View,  extends IActivityLifeCycleAware> extends OverlayContainer<T>
  implements View.OnClickListener, Runnable
{
  private static final int MILLISECONDS_IN_SECOND = 1000;
  int mCloseButtonActivationTimeout;
  protected final Handler mHandler = new Handler();
  private boolean mHasDefaultFullscreenFlag;
  private boolean mHasDefaultNoLimitFlag;
  private Integer mInterstitialShowtime;
  private final String mNetworkName;

  public FullscreenOverlayContainer(T paramT, String paramString)
  {
    super((ViewGroup)((Activity)paramT.getContext()).getWindow().getDecorView(), paramT);
    this.mNetworkName = paramString;
  }

  protected View addChildToLayout(ViewGroup paramViewGroup, T paramT)
  {
    Object localObject1 = BurstlyFullscreenActivity.getDecorator(this.mNetworkName);
    if (localObject1 == null)
      localObject1 = new DefaultInterstitialDecorator()
      {
        protected CloseableContainer<T> createContainer(Activity paramAnonymousActivity)
        {
          CloseableContainer localCloseableContainer = FullscreenOverlayContainer.this.createCloseableContainer();
          if ((localCloseableContainer != null) && (FullscreenOverlayContainer.this.mCloseButtonActivationTimeout != 0))
            localCloseableContainer.setShowCloseButtonDelay(FullscreenOverlayContainer.this.mCloseButtonActivationTimeout);
          return localCloseableContainer;
        }
      };
    Object localObject2 = ((BurstlyFullscreenActivity.IDecorator)localObject1).decorate(paramT, this);
    if (localObject2 == null)
    {
      LOG.logWarning(TAG, "Decorate view is null! Will use original one.", new Object[0]);
      localObject2 = paramT;
    }
    paramT.requestFocus(130);
    paramViewGroup.addView((View)localObject2);
    return localObject2;
  }

  protected CloseableContainer<T> createCloseableContainer()
  {
    CloseableContainer localCloseableContainer = new CloseableContainer(getContext());
    localCloseableContainer.setBackgroundColor(0);
    return localCloseableContainer;
  }

  protected ViewGroup createContainerLayout()
  {
    FrameLayout local2 = new FrameLayout(getContext())
    {
      public boolean dispatchKeyEvent(KeyEvent paramAnonymousKeyEvent)
      {
        switch (paramAnonymousKeyEvent.getKeyCode())
        {
        default:
          return super.dispatchKeyEvent(paramAnonymousKeyEvent);
        case 4:
        }
        if (!super.dispatchKeyEvent(paramAnonymousKeyEvent))
          FullscreenOverlayContainer.this.hideOverlayed();
        return true;
      }

      public boolean onTouchEvent(MotionEvent paramAnonymousMotionEvent)
      {
        super.onTouchEvent(paramAnonymousMotionEvent);
        return true;
      }
    };
    local2.setBackgroundColor(0);
    return local2;
  }

  public int getCloseButtonActivationTimeout()
  {
    return this.mCloseButtonActivationTimeout;
  }

  public Integer getInterstitialShowtime()
  {
    return this.mInterstitialShowtime;
  }

  public void hideOverlayed()
  {
    if (isShowing())
    {
      super.hideOverlayed();
      Window localWindow = ((Activity)getContext()).getWindow();
      if (!this.mHasDefaultFullscreenFlag)
        localWindow.clearFlags(1024);
      if (!this.mHasDefaultNoLimitFlag)
        localWindow.clearFlags(512);
      this.mHandler.removeCallbacks(this);
    }
  }

  public void onClick(View paramView)
  {
    hideOverlayed();
  }

  public void onPause(Activity paramActivity)
  {
    super.onPause(paramActivity);
    this.mHandler.removeCallbacks(this);
  }

  public void onResume(Activity paramActivity)
  {
    super.onResume(paramActivity);
    if (getInterstitialShowtime() != null)
      this.mHandler.postDelayed(this, 1000 * getInterstitialShowtime().intValue());
  }

  public void run()
  {
    hideOverlayed();
  }

  public void setCloseButtonActivationTimeout(int paramInt)
  {
    this.mCloseButtonActivationTimeout = paramInt;
  }

  public void setInterstitialShowtime(Integer paramInteger)
  {
    if ((paramInteger != null) && (paramInteger.intValue() > 0))
      this.mInterstitialShowtime = paramInteger;
  }

  public void showOverlayed()
  {
    boolean bool1 = true;
    if (!isShowing())
    {
      super.showOverlayed();
      Window localWindow = ((Activity)getContext()).getWindow();
      WindowManager.LayoutParams localLayoutParams = localWindow.getAttributes();
      boolean bool2;
      if ((0x400 & localLayoutParams.flags) != 0)
      {
        bool2 = bool1;
        this.mHasDefaultFullscreenFlag = bool2;
        if (!this.mHasDefaultFullscreenFlag)
          localWindow.addFlags(1024);
        if ((0x200 & localLayoutParams.flags) == 0)
          break label131;
      }
      while (true)
      {
        this.mHasDefaultNoLimitFlag = bool1;
        if (!this.mHasDefaultNoLimitFlag)
          localWindow.addFlags(512);
        if (getInterstitialShowtime() != null)
          this.mHandler.postDelayed(this, 1000 * getInterstitialShowtime().intValue());
        return;
        bool2 = false;
        break;
        label131: bool1 = false;
      }
    }
    LOG.logWarning(TAG, "Can not show overlayed view due its top most parent has not been set before.", new Object[0]);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.FullscreenOverlayContainer
 * JD-Core Version:    0.6.2
 */